/******************************************************************************
** 公司名称：天津柯迪斯科技有限公司
** 版权信息：
** 文件名称： App_Display.c
** 模块名称： KD716-AT32F415CBT7显示模块
** 版 本 号： V1.0
** 作    者： 蒲磊
**
** 修改记录： 版本     修改人      时间         修改内容
**
******************************************************************************/

/******************************************************************************
* 头文件
******************************************************************************/
#include "App_Display.h"
#include "App_MainTask.h"
#include "App_Parameter.h"
/******************************************************************************
*宏定义 ('#define')
******************************************************************************/
#define SOFTWARE        "02"          /*软件号*/
#define VER             "10800"       /*版本号*/
/******************************************************************************
*类型定义 ('typedef')
******************************************************************************/

/******************************************************************************
*函数声明 ('static')
******************************************************************************/
extern uint8_t gucVoltage_Calibration;      /*电压校准标志*/
extern uint8_t gucUSBstate;
extern uint8_t gucUsb5minFlag;     /*USB 5分钟标志*/
/******************************************************************************
* 全局变量定义
******************************************************************************/
uint8_t  gucInPasswordFlag = 0;         /*该变量用于标记是否在密码界面*/
const uint8_t KM_MPH_UP[] =   {2,4,7,10,12,15,18,20,23,26,28,31,34,36,39,41,44,47,49,52,55,57,60,63,65,68,70,73,76,78,81,84,86,89,92,94,97,100};
const uint8_t KM_MPH_DOWN[] = {1,3,6,9,11,14,17,19,22,25,27,30,33,35,38,40,43,46,48,51,54,56,59,62,64,67,69,72,75,77,80,83,85,88,91,93,96,99};
/*****************************************************************************
* 函数实现 - global ('extern') and local ('static')
******************************************************************************/

/******************************************************************************
** 功  能：查找给定的数值，是否在一个固定的数值序列中
** 参  数：pTab-固定序列指针，Length-固定序列长度，Data-要查找的数据
** 返回值：0-未查到，其它值-在当前序列中的位置需要（从1开始的）
** 备  注：
******************************************************************************/
uint8_t ucFind_Data(const uint8_t *pTab,uint16_t Length,uint8_t Data)
{
    uint16_t n;
    for(n = 0; n < Length; n++)
    {
        if(*(pTab + n) == Data)
        {
            return n + 1;
        }
    }
    return 0;
}


/******************************************************************************
** 功  能：716仪表全显界面
** 参  数：无
** 返回值：无
** 备  注：
******************************************************************************/
En_FunResponse xDisp_DispAll(void)
{
    uint32_t                    lulTicks;
    muilt_cyc_fifo_error_code_t lxState;
    uint16_t                    lxActualReadLen;
    uint16_t                     lusKeyValue;

    lulTicks = ulBsp_Getticks();

    while(1)
    {
        vBsp_LCD_DispAll();     /*界面全显*/
        //vBsp_LCD_Hide_Navigation();
        vBsp_LCD_Refresh();
        //while(1){}
        if(ulBsp_Getticks() - lulTicks > 2000)
        {
            vBsp_LCD_Clear();           /*界面全显2秒后，先清屏，然后转正常界面显示*/

#if CONFIG_VOL_CHANGE == 1
            if(Read_key_1 == KEY_LEVEL && Read_key_3 == KEY_LEVEL && Read_key_4 == KEY_LEVEL)
            {
                return Page_Voltage_Change;
            }
#endif
            if(gtParam.Password_Start_En)
            {
                return Page_Password_P1_PowerON;
            }
            else
            {
                return Page_MainPage;
            }
        }

        /*从按键缓存中读取键值，并根据键值执行相应的动作*/
        MCF_ReadDataFromFifo(KEY_FIFO_ID,2,(uint8_t *)&lusKeyValue,&lxActualReadLen,&lxState);/*从队列中取出一组键值*/
        if(lxActualReadLen == 2 && lxState == kMultiCycFiFo_Error_NONE)
        {
            switch(lusKeyValue)
            {
            case BUTTON_UP_RELEASE:     /*加键释放*/
            {
                break;
            }
            case BUTTON_DOWN_RELEASE:    /*减键释放*/
            {
                break;
            }
            case BUTTON_UP_LONG:        /*加减长按*/
            {
                break;
            }
            case BUTTON_MODE_RELEASE:   /*i键释放*/
            {
                break;
            }
            }
        }
    }
}

/******************************************************************************
** 功  能：716电压校准界面
** 参  数：无
** 返回值：无
** 备  注：
******************************************************************************/
En_FunResponse xDisp_VoltageCalibration(void)
{
    uint32_t                     lulTicks;
    muilt_cyc_fifo_error_code_t  lxState;
    uint16_t                     lxActualReadLen;
    uint16_t                     lusKeyValue;

    lulTicks = ulBsp_Getticks();

    while(1)
    {
        vBsp_LCD_DispSpeedNum(CONFIG_DEF_VOL * 10,ON);   /*显示默认电压值*/

        if(ulBsp_Getticks() - lulTicks > 1000)
        {
            vBsp_LCD_Clear();           /*界面全显2秒后，先清屏，然后转正常界面显示*/
            return Page_MainPage;
        }

        /*从按键缓存中读取键值，并根据键值执行相应的动作*/
        MCF_ReadDataFromFifo(KEY_FIFO_ID,2,(uint8_t *)&lusKeyValue,&lxActualReadLen,&lxState);/*从队列中取出一组键值*/
        if(lxActualReadLen == 2 && lxState == kMultiCycFiFo_Error_NONE)
        {
            switch(lusKeyValue)
            {
            case BUTTON_UP_RELEASE:     /*加键释放*/
            {
                break;
            }
            case BUTTON_DOWN_RELEASE:    /*减键释放*/
            {
                break;
            }
            case BUTTON_UP_LONG:        /*加减长按*/
            {
                break;
            }
            case BUTTON_MODE_RELEASE:   /*i键释放*/
            {
                break;
            }
            }
        }
    }
}

/******************************************************************************
** 功  能：716电压切换界面
** 参  数：无
** 返回值：无
** 备  注：
******************************************************************************/
En_FunResponse xDisp_VoltageChange(void)
{
    uint32_t                    lulTicks;
    muilt_cyc_fifo_error_code_t lxState;
    uint16_t                    lxActualReadLen;
    uint16_t                     lusKeyValue;
    uint8_t                     lucChangedVoltage;

    lulTicks = ulBsp_Getticks();

#if (CONFIG_VOL_RANGE == VOL_36_48)
    lucChangedVoltage = gtParam.Volt == 36 ? 48:36;
#elif (CONFIG_VOL_RANGE == VOL_36_48_52)
    if(gtParam.Volt == 36)
    {
        lucChangedVoltage = 48;
    }
    else if(gtParam.Volt == 48)
    {
        lucChangedVoltage = 52;
    }
    else if(gtParam.Volt == 52)
    {
        lucChangedVoltage = 36;
    }
#endif

    while(1)
    {
        if(ulBsp_Getticks() - lulTicks < 1000)
        {
            vBsp_LCD_DispSpeedNum(gtParam.Volt * 10,ON);        /*前一秒显示原来的电压值*/
        }
        else if(ulBsp_Getticks() - lulTicks < 2000)
        {
            vBsp_LCD_DispSpeedNum(lucChangedVoltage * 10,ON);   /*后一秒显示切换后的电压值*/
        }
        else
        {
            gtParam.Volt = lucChangedVoltage;
            vParam_Write(&gtParam,ConfigInfo);      /*保存参数*/
            vBsp_LCD_Clear();           /*界面全显2秒后，先清屏，然后转正常界面显示*/
            return Page_MainPage;
        }

        /*从按键缓存中读取键值，并根据键值执行相应的动作*/
        MCF_ReadDataFromFifo(KEY_FIFO_ID,2,(uint8_t *)&lusKeyValue,&lxActualReadLen,&lxState);/*从队列中取出一组键值*/
        if(lxActualReadLen == 2 && lxState == kMultiCycFiFo_Error_NONE)
        {
            switch(lusKeyValue)
            {
            case BUTTON_UP_RELEASE:     /*加键释放*/
            {
                break;
            }
            case BUTTON_DOWN_RELEASE:    /*减键释放*/
            {
                break;
            }
            case BUTTON_UP_LONG:        /*加减长按*/
            {
                break;
            }
            case BUTTON_MODE_RELEASE:   /*i键释放*/
            {
                break;
            }
            }
        }
    }
}

/******************************************************************************
** 功  能：716仪表主界面显示
** 参  数：无
** 返回值：无
** 备  注：
******************************************************************************/
En_FunResponse xDisp_MainPage(void)
{
    muilt_cyc_fifo_error_code_t lxState;
    uint16_t                    lxActualReadLen;
    uint16_t                     lusKeyValue;
    En_DisplayMode              lxDisplayMode = Display_Speed;
    uint16_t                    lusVolt;
    int8_t                      lscSoc = 0;
    uint8_t                     lucWalk = 0;        /*助推标志*/

    vPROTOCOL_Set_Pas(gcPas);
    HAL_TIM_Base_Start_IT(&htim14);              /*开启秒中断，用于里程统计、电量缓降等*/

    while(1)
    {
        if(gucVoltage_Calibration)
        {
            vBsp_LCD_Clear();
            return Page_VoltageCalibration;
        }

        /*大灯图标显示*/
        vBsp_LCD_DispICO_Lamp(gucLamp);
        /*充电图标显示*/
        vBsp_LCD_DispICO_USB(gucUSBstate);
#if USE_BLUETOOTH
        /*蓝牙图标显示*/
        if(mcu_get_bt_work_state() == BT_CONNECTED)
        {
            vBsp_LCD_DispICO_Bluetooth(ON);
        }
        else
        {
            vBsp_LCD_DispICO_Bluetooth(OFF);
        }
#endif
        /*挡位显示*/
        if(lucWalk)
        {
            /*助推时，闪烁助推标志*/
            vBsp_LCD_DispPas(-1,ucBsp_GetFlashFlag());

        }
        else
        {
            /*正常显示挡位*/
            vBsp_LCD_DispPas(gcPas,1);
            /*挡位上面的横线显示*/
            vBsp_LCD_DispPasLine(gcPas,1);
        }



        /*底部的横线*/
        vBsp_LCD_DispICO_Line(1);

        /*读取电压,采用自采电压*/
        lusVolt = ulGet_Sys_Voltage() / 100;

        /*读取电量，如果为-1，表示不支持电量。如果允许自采电压显示SOC，则根据电压计算SOC，否则显示0*/
        lscSoc = cPROTOCOL_Get_Soc();
        if(lscSoc == -1)
        {
#if (CONFIG_SELF_SAMPLING == 1) /*允许电压自采样显示电量*/
            if(ulBsp_Getticks() > 3000)     /*开机3秒以后，如果仍没有读取到SOC，则采用自采*/
            {
                lscSoc  = ucGet_Battery_Soc(lusVolt);
            }
#else
            lscSoc = 0;
#endif
        }

        /*电量显示*/
        vLCD_DispSoc(lscSoc,gtParam.V_BMS_Tab[4],gtParam.V_BMS_Tab[3],gtParam.V_BMS_Tab[2],gtParam.V_BMS_Tab[1],gtParam.V_BMS_Tab[0]);

        /*速度、最高速、平均速显示*/
        switch(lxDisplayMode)
        {
        case Display_MaxSpeed:
        {
            vBsp_LCD_DispMaxSpeed(gtRiding.Speed_Max,gtParam.Unit,1);
            break;
        }
        case Display_AvgSpeed:
        {
            vBsp_LCD_DispAvgSpeed(gtRiding.Speed_Avg,gtParam.Unit,1);
            break;
        }
        default:
        {
            vBsp_LCD_DispSpeed(usPROTOCOL_Get_Speed(),gtParam.Unit,1);      /*速度显示*/

            break;
        }
        }

        if(ucPROTOCOL_Get_Errcode() != 0)
        {
            vBsp_LCD_DispErrorCode(ucPROTOCOL_Get_Errcode());
        }
        else
        {
            vBsp_LCD_DispICO_Service(0);            /*没有报错时，不显示服务扳手图标*/

            /*Trip、ODO、Time、Power显示*/
            switch(lxDisplayMode)
            {
            case Display_Odo:   /*显示ODO*/
            {
                vBsp_LCD_DispOdo(gtRiding.ODO / 10000,gtParam.Unit,1);
                break;
            }
            case Display_Time:  /*显示Time*/
            {

                vBsp_LCD_DispTime(gtRiding.Riding_Time / 60,1);
                break;
            }
            case Display_Power: /*显示功率*/
            {
                vBsp_LCD_DispPower(lusVolt * usPROTOCOL_Get_Current() / 100,1);
                break;
            }
            default:    /*默认显示Trip*/
            {
                vBsp_LCD_DispTrip(gtRiding.Trip / 1000,gtParam.Unit,1);
                break;
            }
            }
        }

        if (gucUsb5minFlag == 1)
        {
            gucUsb5minFlag = 0;
            return Page_UsbCharging;
        }

        /*从按键缓存中读取键值，并根据键值执行相应的动作*/
        MCF_ReadDataFromFifo(KEY_FIFO_ID,2,(uint8_t *)&lusKeyValue,&lxActualReadLen,&lxState);/*从队列中取出一组键值*/
        if(lxActualReadLen == 2 && lxState == kMultiCycFiFo_Error_NONE)
        {
            switch(lusKeyValue)
            {
            case BUTTON_UP_RELEASE:     /*加键释放*/
            {
                if(gcPas < gtParam.Pas_Max)
                {
                    gcPas++;
                }
                vPROTOCOL_Set_Pas(gcPas);

                break;
            }
            case BUTTON_DOWN_RELEASE:    /*减键释放*/
            {
                if(gcPas > gtParam.Pas_Min)
                {
                    gcPas--;
                }
                vPROTOCOL_Set_Pas(gcPas);

                break;
            }
#if (KEY_MODE == K5)
            case BUTTON_LAMP_RELEASE:
#else
            case BUTTON_UP_LONG:        /*加减长按*/
#endif
            {
                vToggle_Lamp_Manual();
                break;
            }
            case BUTTON_DOWN_LONG:      /*减键长按*/
            {
                lucWalk = 1;
                vPROTOCOL_Set_Pas(-1);
                break;
            }
            case BUTTON_DOWN_CONTINUE_RELEASE:  /*减键连发释放*/
            {
                lucWalk = 0;
                vPROTOCOL_Set_Pas(gcPas);
                break;
            }
            case BUTTON_MODE_RELEASE:   /*i键释放*/
            {
                if(++lxDisplayMode > Display_Power)
                {
                    lxDisplayMode = Display_Speed;
                }

                break;
            }
            case BUTTON_MODE_LONG:  /*i键长按*/
            {
//                    if(++gtParam.Mode > 3)
//                    {
//                        gtParam.Mode = 1;
//                    }

//                    vParam_Write(&gtParam,ConfigInfo);
                break;
            }
            case BUTTON_UP_DOWN_LONG:    /*加减键长按*/
            {
                if(usPROTOCOL_Get_Speed() == 0)
                {
                    vBsp_LCD_Clear();
                    vEnter_Setting();
                    return Page_Setting;     /*先清屏，然后转入设置界面*/
                }
                break;
            }
            case BUTTON_POWER_LONG:     /*电源键长按*/
            {
                vPowerOff();
                break;
            }
            case BUTTON_R_RELEASE: //右转向
            {
                gucTurnLeftLamp = 0;
                gucTurnRightLamp  = !gucTurnRightLamp;
                //vPROTOCOL_Set_Turn_Lamp(gucTurnRightLamp);
                vPROTOCOL_Set_TurnRight(gucTurnRightLamp);
                vPROTOCOL_Set_TurnLeft(gucTurnLeftLamp);


                if(gucTurnRightLamp)
                {
                    ICO_LIGHT_LEFT_OFF;
                    ICO_LIGHT_RIGHT_ON;
                }
                else
                {
                    ICO_LIGHT_LEFT_OFF;
                    ICO_LIGHT_RIGHT_OFF;
                }

                break;

                break;
            }
            case BUTTON_L_RELEASE:
            {
                gucTurnRightLamp = 0;
                gucTurnLeftLamp  = !gucTurnLeftLamp;
                //vPROTOCOL_Set_Turn_Lamp(gucTurnLeftLamp);
                vPROTOCOL_Set_TurnLeft(gucTurnLeftLamp);
                vPROTOCOL_Set_TurnRight(gucTurnRightLamp);
                if(gucTurnLeftLamp)
                {
                    ICO_LIGHT_LEFT_ON;
                    ICO_LIGHT_RIGHT_OFF;
                }
                else
                {
                    ICO_LIGHT_LEFT_OFF;
                    ICO_LIGHT_RIGHT_OFF;
                }

                break;
            }
            case BUTTON_DOWN_MODE_LONG: /*减键和i键长按，解绑蓝牙*/
            {
                if(usPROTOCOL_Get_Speed() == 0)
                {
                    vBsp_LCD_Clear();
                    return Page_Set_Default;
                }
                break;
            }
            }
        }
    }
}


/******************************************************************************
** 功  能：716仪表设置界面显示
** 参  数：无
** 返回值：无
** 备  注：
******************************************************************************/
En_FunResponse xDisp_Setting(void)
{
    muilt_cyc_fifo_error_code_t lxState;
    uint16_t                    lxActualReadLen;
    uint16_t                     lusKeyValue;
    En_Setting                  lxDispIndex = Setting_ClearTrip;
    uint32_t                    lulTicks;
    uint8_t                     lucClearTrip = 0;

    vPROTOCOL_Set_Pas(0);           /*设置界面发0档*/
    lulTicks = ulBsp_Getticks();    /*记录以下进入设置时的时间戳，用于判断超时退出*/
    while(1)
    {
        /*底部的横线*/
        vBsp_LCD_DispICO_Line(1);
        /*MENU图标，显示*/
        vBsp_LCD_DispICO_Menu(1);

        /*根据选择，显示不同的调节参数*/
        switch(lxDispIndex)
        {
        case Setting_ClearTrip:     /*清Trip*/
        {
            vBsp_LCD_DispSetClearTrip(lucClearTrip);
            break;
        }
        case Setting_Backlight:     /*调背光*/
        {
            vBsp_LCD_DispSetBacklight(gtParam.Backlight);
            break;
        }
        case Setting_Unit:          /*设置单位类型*/
        {
            vBsp_LCD_DispSetUnit(gtParam.Unit);
            break;
        }
        default:
            break;
        }

        if(ulBsp_Getticks() - lulTicks > CONFIG_EXTI_TIME * 1000)
        {
            vExit_Setting_Without_Saving();     /*超时退出，不保存设置*/
            vBsp_LCD_DispAll();
            vBsp_DelayMs(500);
            vBsp_LCD_Clear();
            return Page_MainPage;    /*全显0.5秒后，转主界面*/
        }

        /*从按键缓存中读取键值，并根据键值执行相应的动作*/
        MCF_ReadDataFromFifo(KEY_FIFO_ID,2,(uint8_t *)&lusKeyValue,&lxActualReadLen,&lxState);/*从队列中取出一组键值*/
        if(lxActualReadLen == 2 && lxState == kMultiCycFiFo_Error_NONE)
        {
            lulTicks = ulBsp_Getticks();        /*有任何按键按下，都会复位自动退出超时计数*/
            switch(lusKeyValue)
            {
            case BUTTON_UP_RELEASE:     /*加键释放*/
            {
                switch(lxDispIndex)
                {
                case Setting_ClearTrip:
                {
                    lucClearTrip = lucClearTrip == 0 ? 1:0;
                    break;
                }
                case Setting_Backlight:
                {
                    if(++gtParam.Backlight > 5)
                    {
                        gtParam.Backlight = 1;
                    }
                    vBsp_SetBacklight(ucGet_Backlight_Precent(gtParam.Backlight));
                    break;
                }
                case Setting_Unit:
                {
                    gtParam.Unit = gtParam.Unit == 0 ? 1:0;
                    break;
                }
                default:
                    break;
                }
                break;
            }
            case BUTTON_DOWN_RELEASE:    /*减键释放*/
            {
                switch(lxDispIndex)
                {
                case Setting_ClearTrip:
                {
                    lucClearTrip = lucClearTrip == 0 ? 1:0;
                    break;
                }
                case Setting_Backlight:
                {
                    if(--gtParam.Backlight < 1)
                    {
                        gtParam.Backlight = 5;
                    }
                    vBsp_SetBacklight(ucGet_Backlight_Precent(gtParam.Backlight));
                    break;
                }
                case Setting_Unit:
                {
                    gtParam.Unit = gtParam.Unit == 0 ? 1:0;
                    break;
                }
                default:
                    break;
                }
                break;
            }
            case BUTTON_UP_LONG:        /*加键长按*/
            {

                break;
            }
            case BUTTON_MODE_RELEASE:   /*i键释放*/
            {
                if(++lxDispIndex > Setting_Unit)
                {
                    lxDispIndex = Setting_ClearTrip;
                }
                /*当切换到背光调节界面时，立即更新以下当前背光亮度*/
                if(lxDispIndex == Setting_Backlight)
                {
                    vBsp_SetBacklight(ucGet_Backlight_Precent(gtParam.Backlight));
                }
                if(lucClearTrip)
                {

                    vParam_ResetRiding_Without_ODO(&gtRiding);  /*复位骑行参数*/

                    lucClearTrip = 0;
                }
                break;
            }

            case BUTTON_MODE_LONG:      /*长按i键*/
            {
                if(lucClearTrip)
                {

                    vParam_ResetRiding_Without_ODO(&gtRiding);  /*复位骑行参数*/

                    lucClearTrip = 0;
                }
                vExit_Setting_With_Saving();    /*保存参数*/
                vBsp_LCD_DispAll();
                vBsp_DelayMs(500);
                vBsp_LCD_Clear();
                return Page_MainPage;    /*全显0.5秒后，转主界面*/
            }
            case BUTTON_UP_DOWN_LONG:    /*加减键长按*/
            {
                vBsp_LCD_Clear();

                return Page_DispVersion;    /*转版本号显示界面*/ //=因为不让进入个性化设置，故直接进入软件版本界面
                if(CONFIG_SETTING_PASSWORD_EN)
                {
                    return Page_Password_P4_Setting;     /*设置密码使能，先清屏，然后转入高级设置密码界面*/
                }
                else
                {
                    return Page_AdvancedSetting;         /*设置界面不使能，先清屏，然后直接进入高级设置菜单*/
                }
            }
            case BUTTON_DOWN_MODE_LONG:     /*减键和i键长按，进轮径和限速设置界面*/
            {
                vBsp_LCD_Clear();
                if(CONFIG_SETTING_PASSWORD_EN)
                {
                    return Page_Password_P5_SetWheel;     /*设置密码使能，先清屏，然后转入轮径设置密码界面*/
                }
                else
                {
                    return Page_SetWheel;         /*设置界面不使能，先清屏，然后直接进入高级设置菜单*/
                }
            }
            }
        }
    }
}

/******************************************************************************
** 功  能：716仪表高级设置界面显示
** 参  数：无
** 返回值：无
** 备  注：
******************************************************************************/
En_FunResponse xDisp_AdvancedSetting(void)
{
    muilt_cyc_fifo_error_code_t lxState;
    uint16_t                    lxActualReadLen;
    uint16_t                     lusKeyValue;
    En_Setting                  lxDispIndex;
    uint32_t                    lulTicks;


    vPROTOCOL_Set_Pas(0);           /*设置界面发0档*/
    lulTicks = ulBsp_Getticks();    /*记录以下进入设置时的时间戳，用于判断超时退出*/
    lxDispIndex = Setting_Voltage;
    while(1)
    {
        /*底部的横线*/
        vBsp_LCD_DispICO_Line(1);
        /*MENU图标，显示*/
        vBsp_LCD_DispICO_Menu(1);

        /*根据选择，显示不同的调节参数*/
        switch(lxDispIndex)
        {

        case Setting_Voltage:     /*设置电压分段*/
        {
            vBsp_LCD_DispStringAtSpeed("UOL",ON);
            break;
        }
        case Setting_ScaPasRange:          /*设置挡位范围*/
        {
            vBsp_LCD_DispStringAtSpeed("SCA",ON);
            break;
        }
        case Setting_Password:     /*设置密码*/
        {
            vBsp_LCD_DispStringAtSpeed("PSD",ON);
            break;
        }
        default:
            break;
        }

        if(ulBsp_Getticks() - lulTicks > 60000)
        {
            vExit_Setting_Without_Saving();     /*超时退出，不保存设置*/
            vBsp_LCD_DispAll();
            vBsp_DelayMs(500);
            vBsp_LCD_Clear();
            return Page_MainPage;    /*全显0.5秒后，转主界面*/
        }

        /*从按键缓存中读取键值，并根据键值执行相应的动作*/
        MCF_ReadDataFromFifo(KEY_FIFO_ID,2,(uint8_t *)&lusKeyValue,&lxActualReadLen,&lxState);/*从队列中取出一组键值*/
        if(lxActualReadLen == 2 && lxState == kMultiCycFiFo_Error_NONE)
        {
            lulTicks = ulBsp_Getticks();        /*有任何按键按下，都会复位自动退出超时计数*/
            switch(lusKeyValue)
            {
            case BUTTON_UP_RELEASE:     /*加键释放*/
            {
                /*此处不需要调节电压分段和挡位，屏蔽调节*/
                if(++lxDispIndex > Setting_Password)
                {
                    lxDispIndex = Setting_Voltage;
                }
                break;
            }
            case BUTTON_DOWN_RELEASE:    /*减键释放*/
            {
                /*此处不需要调节电压分段和挡位，屏蔽调节*/
                if(--lxDispIndex < Setting_Voltage)
                {
                    lxDispIndex = Setting_Password;
                }
                break;
            }
            case BUTTON_UP_LONG:        /*加减长按*/
            {

                break;
            }
            case BUTTON_MODE_RELEASE:   /*i键释放*/
            {
                switch(lxDispIndex)
                {
                case Setting_Password:     /*设置密码*/
                {
                    vBsp_LCD_Clear();
                    return Page_Password_P2_Input;       /*进入密码确认界面*/

                }
                case Setting_Voltage:     /*设置电压分段*/
                {
                    vBsp_LCD_Clear();
                    return Page_Voltage_Segment;     /*转到电压分段设置页面*/
                }
                case Setting_ScaPasRange:          /*设置挡位范围*/
                {
                    return Page_Sca_SetPwm;
                    break;
                }
                default:
                    break;
                }
                break;
            }
            case BUTTON_UP_DOWN_LONG:   /*高级设置中，加减键长按，进入版本号显示界面*/
            {
                vBsp_LCD_Clear();
                return Page_DispVersion;    /*转版本号显示界面*/
            }
            case BUTTON_MODE_LONG:      /*长按i键,K3按键，电源键和i键是一个*/
            {
                vExit_Setting_With_Saving();    /*保存参数*/
                vBsp_LCD_DispAll();
                vBsp_DelayMs(500);
                vBsp_LCD_Clear();
                return Page_MainPage;    /*全显0.5秒后，转主界面*/
            }
            case BUTTON_POWER_LONG: /*电源键长按*/
            {
                vPowerOff();
                break;
            }
            }
        }
    }
}
/******************************************************************************
** 功  能：716仪表轮径和限速设置界面显示
** 参  数：无
** 返回值：无
** 备  注：
******************************************************************************/
En_FunResponse xDisp_WheelSetting(void)
{
    muilt_cyc_fifo_error_code_t lxState;
    uint16_t                    lxActualReadLen;
    uint16_t                     lusKeyValue;
    En_Setting                  lxDispIndex;
    uint32_t                    lulTicks;
    uint8_t                     lucType;

    vPROTOCOL_Set_Pas(0);           /*设置界面发0档*/
    lulTicks = ulBsp_Getticks();    /*记录以下进入设置时的时间戳，用于判断超时退出*/
    lxDispIndex = Setting_Wheel;
    lucType = 1;        /*初始状态，处于调节限速和轮径的过程，此时LS后者LD闪烁*/

    while(1)
    {
        /*底部的横线*/
        vBsp_LCD_DispICO_Line(1);
        /*MENU图标，显示*/
        vBsp_LCD_DispICO_Menu(1);

        /*根据选择，显示不同的调节参数*/
        switch(lxDispIndex)
        {
        case Setting_Wheel:     /*轮径设置*/
        {
            vBsp_LCD_DispSetWheel(usGet_Wheel_Size(gtParam.Wheel_Diameter),lucType);
            break;
        }
        case Setting_LimitSpeed:     /*限速设置*/
        {
            vBsp_LCD_DispSetLimitSpeed(gtParam.Speed_Limit,gtParam.Unit,lucType);
            break;
        }

        default:
            break;
        }

        if(ulBsp_Getticks() - lulTicks > CONFIG_EXTI_TIME * 1000)
        {
            vExit_Setting_Without_Saving();     /*超时退出，不保存设置*/
            vBsp_LCD_DispAll();
            vBsp_DelayMs(500);
            vBsp_LCD_Clear();
            return Page_MainPage;    /*全显0.5秒后，转主界面*/
        }

        /*从按键缓存中读取键值，并根据键值执行相应的动作*/
        MCF_ReadDataFromFifo(KEY_FIFO_ID,2,(uint8_t *)&lusKeyValue,&lxActualReadLen,&lxState);/*从队列中取出一组键值*/
        if(lxActualReadLen == 2 && lxState == kMultiCycFiFo_Error_NONE)
        {
            lulTicks = ulBsp_Getticks();        /*有任何按键按下，都会复位自动退出超时计数*/
            switch(lusKeyValue)
            {
            case BUTTON_UP_RELEASE:     /*加键释放*/
            {
                if(lucType == 1)    /*处于选择限速还是轮径的界面*/
                {
                    lxDispIndex = lxDispIndex == Setting_Wheel ? Setting_LimitSpeed : Setting_Wheel;
                }
                else    /*处于调节参数界面*/
                {
                    switch(lxDispIndex)
                    {
                    case Setting_Wheel:     /*轮径设置*/
                    {
                        if(CONFIG_WHEEL_SIZE_CHANGE_EN)
                        {
                            /*允许轮径调节，且支持巡航调节*/
                            if(++gtParam.Wheel_Diameter > CONFIG_DIAMETER_MAX)
                            {
                                gtParam.Wheel_Diameter = CONFIG_DIAMETER_MIN;
                            }
                        }
                        break;
                    }
                    case Setting_LimitSpeed:     /*限速设置*/
                    {
                        if(CONFIG_SPEED_LIMIT_CHANGE_EN)
                        {
                            /*允许限速调节*/
                            gtParam.Speed_Limit++;
                            if(gtParam.Unit == 1)
                            {
                                if(ucFind_Data(KM_MPH_UP,sizeof(KM_MPH_UP)/sizeof(uint8_t),gtParam.Speed_Limit))
                                {
                                    gtParam.Speed_Limit++;
                                }
                            }
                            if(gtParam.Speed_Limit > CONFIG_SPEED_MAX)
                            {
                                gtParam.Speed_Limit = CONFIG_SPEED_MIN;
                            }
                        }
                        break;
                    }
                    default:
                        break;
                    }
                }
                break;
            }
            case BUTTON_DOWN_RELEASE:    /*减键释放*/
            {
                if(lucType == 1)    /*处于选择限速还是轮径的界面*/
                {
                    lxDispIndex = lxDispIndex == Setting_Wheel ? Setting_LimitSpeed : Setting_Wheel;
                }
                else    /*处于调节参数界面*/
                {
                    switch(lxDispIndex)
                    {
                    case Setting_Wheel:     /*轮径设置*/
                    {
                        if(CONFIG_WHEEL_SIZE_CHANGE_EN)
                        {
                            /*允许轮径调节，且支持巡航调节*/
                            if(gtParam.Wheel_Diameter-- == CONFIG_DIAMETER_MIN)
                            {
                                gtParam.Wheel_Diameter = CONFIG_DIAMETER_MAX;
                            }
                        }
                        break;
                    }
                    case Setting_LimitSpeed:     /*限速设置*/
                    {
                        if(CONFIG_SPEED_LIMIT_CHANGE_EN)
                        {
                            /*允许限速调节*/
                            gtParam.Speed_Limit--;
                            if(gtParam.Unit == 1)
                            {
                                if(ucFind_Data(KM_MPH_DOWN,sizeof(KM_MPH_DOWN)/sizeof(uint8_t),gtParam.Speed_Limit))
                                {
                                    gtParam.Speed_Limit--;
                                }
                            }
                            if(gtParam.Speed_Limit < CONFIG_SPEED_MIN)
                            {
                                gtParam.Speed_Limit = CONFIG_SPEED_MAX;
                            }
                        }
                        break;
                    }
                    default:
                        break;
                    }
                }
                break;
            }
            case BUTTON_UP_LONG:        /*加键长按*/
            {
                break;
            }
            case BUTTON_MODE_RELEASE:   /*i键释放*/
            {
                lucType = lucType == 1 ? 2:1;
                break;
            }
            case BUTTON_MODE_LONG:      /*长按i键*/
            {
                vExit_Setting_With_Saving();    /*保存参数*/
                vBsp_LCD_DispAll();
                vBsp_DelayMs(500);
                vBsp_LCD_Clear();
                return Page_MainPage;    /*全显0.5秒后，转主界面*/
            }
            }
        }
    }
}

/******************************************************************************
** 功  能：716仪表密码设置界面显示
** 参  数：PageType-密码界面的界面类型
** 返回值：无
** 备  注：
******************************************************************************/
En_FunResponse xDisp_PasswordSetting(En_FunResponse PageType)
{
    muilt_cyc_fifo_error_code_t lxState;
    uint16_t                    lxActualReadLen;
    uint16_t                     lusKeyValue;
    uint8_t                     lucFlashBit = 0;        /*标记当前密码闪烁的位*/
    uint32_t                    lulTicks;
    uint8_t                     lucPasswordBit[4] = {0};      /*密码每一位对应的数字*/

    vPROTOCOL_Set_Pas(0);           /*密码界面发0档*/
    lulTicks = ulBsp_Getticks();    /*记录以下进入设置时的时间戳，用于判断超时退出*/

    /*如果时密码确认界面，提前填充当前密码*/
    if(PageType == Page_Password_P3_Confim)
    {
        lucPasswordBit[0] = gtParam.Password_Start / 1000;
        lucPasswordBit[1] = gtParam.Password_Start % 1000 / 100;
        lucPasswordBit[2] = gtParam.Password_Start % 100 / 10;
        lucPasswordBit[3] = gtParam.Password_Start % 10;
    }


    while(1)
    {
        /*底部的横线*/
        vBsp_LCD_DispICO_Line(1);

        /*根据选择，显示不同的调节参数*/
        switch(PageType)
        {
        case Page_Password_P1_PowerON:     /*开机密码界面*/
        {
            vBsp_LCD_DispStringAtSpeed("P1",ON);
            vBsp_LCD_DispPasswordNum(lucPasswordBit[0] * 1000 + lucPasswordBit[1] * 100 + lucPasswordBit[2] * 10 + lucPasswordBit[3],lucFlashBit);
            break;
        }
        case Page_Password_P2_Input:     /*密码输入界面*/
        {
            vBsp_LCD_DispStringAtSpeed("P2",ON);
            vBsp_LCD_DispPasswordNum(lucPasswordBit[0] * 1000 + lucPasswordBit[1] * 100 + lucPasswordBit[2] * 10 + lucPasswordBit[3],lucFlashBit);
            break;
        }
        case Page_Password_P3_Confim:   /*密码确认界面*/
        {
            vBsp_LCD_DispStringAtSpeed("P3",ON);
            vBsp_LCD_DispPasswordNum(lucPasswordBit[0] * 1000 + lucPasswordBit[1] * 100 + lucPasswordBit[2] * 10 + lucPasswordBit[3],lucFlashBit);
            break;
        }
        case Page_Password_P4_Setting:  /*设置密码界面*/
        case Page_Password_P5_SetWheel: /*轮径限速设置密码界面*/
        {
            vBsp_LCD_DispStringAtSpeed("P4",ON);
            vBsp_LCD_DispPasswordNum(lucPasswordBit[0] * 1000 + lucPasswordBit[1] * 100 + lucPasswordBit[2] * 10 + lucPasswordBit[3],lucFlashBit);
            break;
        }
        case Page_Password_En:          /*密码使能界面*/
        {
            vBsp_LCD_DispStringAtBottom("PSD-",0,ON);
            if(gtParam.Password_Start_En)
            {
                vBsp_LCD_DispStringAtBottom("y",4,ucBsp_GetFlashFlag());
            }
            else
            {
                vBsp_LCD_DispStringAtBottom("n",4,ucBsp_GetFlashFlag());
            }
            break;
        }

        default:
            break;
        }

        /*不是开机密码界面，做超时10秒退出。开机密码界面，屏蔽超时退出功能*/
        if(PageType != Page_Password_P1_PowerON)
        {
            if(ulBsp_Getticks() - lulTicks > CONFIG_EXTI_TIME * 1000)
            {
                vExit_Setting_Without_Saving();     /*超时退出，不保存设置*/
                vBsp_LCD_DispAll();
                vBsp_DelayMs(500);
                vBsp_LCD_Clear();
                return Page_MainPage;    /*全显0.5秒后，转主界面*/
            }
        }
        else
        {
            /*开机密码界面，1分钟超时后关机*/
            if(ulBsp_Getticks() - lulTicks > 60000)
            {
                vPowerOff();
            }
        }

        /*从按键缓存中读取键值，并根据键值执行相应的动作*/
        MCF_ReadDataFromFifo(KEY_FIFO_ID,2,(uint8_t *)&lusKeyValue,&lxActualReadLen,&lxState);/*从队列中取出一组键值*/
        if(lxActualReadLen == 2 && lxState == kMultiCycFiFo_Error_NONE)
        {
            lulTicks = ulBsp_Getticks();        /*有任何按键按下，都会复位自动退出超时计数*/
            switch(lusKeyValue)
            {
            case BUTTON_UP_RELEASE:     /*加键释放*/
            {
                if(PageType == Page_Password_En)
                {
                    /*密码使能界面，翻转使能标志*/
                    gtParam.Password_Start_En = gtParam.Password_Start_En == 0 ? 1:0;
                }
                else
                {
                    /*调节对应位的密码数字*/
                    if(++lucPasswordBit[lucFlashBit] > 9)
                    {
                        lucPasswordBit[lucFlashBit] = 0;
                    }
                }
                break;
            }
            case BUTTON_DOWN_RELEASE:    /*减键释放*/
            {
                if(PageType == Page_Password_En)
                {
                    /*密码使能界面，翻转使能标志*/
                    gtParam.Password_Start_En = gtParam.Password_Start_En == 0 ? 1:0;
                }
                else
                {
                    /*调节对应位的密码数字*/
                    if(lucPasswordBit[lucFlashBit]-- == 0)
                    {
                        lucPasswordBit[lucFlashBit] = 9;
                    }
                }
                break;
            }
            case BUTTON_POWER_LONG:        /*电源键长按*/
            {
                //if(PageType == Page_Password_P1_PowerON)
                {
                    vPowerOff();
                }
                break;
            }
            case BUTTON_MODE_RELEASE:   /*i键释放*/
            {
                switch(PageType)
                {
                case Page_Password_P1_PowerON:      /*开机密码界面*/
                {
                    if(lucFlashBit == 3 && lucPasswordBit[0] * 1000 + lucPasswordBit[1] * 100 + lucPasswordBit[2] * 10 + lucPasswordBit[3] == gtParam.Password_Start)
                    {
                        /*密码输入正确，清屏后进主界面*/
                        vBsp_LCD_Clear();
                        return Page_MainPage;
                    }
                    else
                    {
                        /*密码输入不正确，循环输入*/
                        if(++lucFlashBit > 3)
                        {
                            lucFlashBit = 0;
                        }
                    }

                    break;
                }
                case Page_Password_P2_Input:    /*密码输入界面*/
                {
                    if(lucFlashBit == 3 && lucPasswordBit[0] * 1000 + lucPasswordBit[1] * 100 + lucPasswordBit[2] * 10 + lucPasswordBit[3] == gtParam.Password_Start)
                    {
                        /*密码输入正确，清屏后进密码使能界面*/
                        vBsp_LCD_Clear();
                        return Page_Password_En;
                    }
                    else
                    {
                        /*密码输入不正确，循环输入*/
                        if(++lucFlashBit > 3)
                        {
                            lucFlashBit = 0;
                        }
                    }
                    break;
                }
                case Page_Password_P3_Confim:   /*密码确认界面*/
                {
                    /*确认密码界面，循环输入，直到长按i键退出*/
                    if(++lucFlashBit > 3)
                    {
                        lucFlashBit = 0;
                    }
                    break;
                }
                case Page_Password_P5_SetWheel: /*进轮径限速设置界面密码*/
                case Page_Password_P4_Setting:  /*进设置的密码界面*/
                {
                    if(lucFlashBit == 3 && lucPasswordBit[0] * 1000 + lucPasswordBit[1] * 100 + lucPasswordBit[2] * 10 + lucPasswordBit[3] == gtParam.Password_Setting)
                    {
                        /*密码输入正确，清屏后进高级设置界面*/
                        vBsp_LCD_Clear();
                        if(PageType == Page_Password_P4_Setting)
                        {
                            return Page_AdvancedSetting;        /*转到高级设置菜单*/
                        }
                        else if(PageType == Page_Password_P5_SetWheel)
                        {
                            return Page_SetWheel;               /*转到设置轮径界面*/
                        }
                    }
                    else
                    {
                        /*密码输入不正确，循环输入*/
                        if(++lucFlashBit > 3)
                        {
                            lucFlashBit = 0;
                        }
                    }
                    break;
                }
                case Page_Password_En:      /*密码使能选项界面*/
                {
                    if(gtParam.Password_Start_En)
                    {
                        vBsp_LCD_Clear();
                        return Page_Password_P3_Confim;     /*密码使能，转向密码确认界面*/
                    }
                    else
                    {
                        vBsp_LCD_Clear();
                        return Page_AdvancedSetting;    /*密码不使能，直接退回到高级设置界面*/
                    }
                }
                default:
                    break;
                }
                break;
            }
            case BUTTON_MODE_LONG:      /*长按i键*/
            {
                if(PageType == Page_Password_P3_Confim)     /*密码设置界面长按i键，返回到高级设置菜单*/
                {
                    gtParam.Password_Start = lucPasswordBit[0] * 1000 + lucPasswordBit[1] * 100 + lucPasswordBit[2] * 10 + lucPasswordBit[3];
                    vBsp_LCD_Clear();
                    return Page_AdvancedSetting;    /*转高级设置界面*/
                }
                if(PageType == Page_Password_P4_Setting || PageType == Page_Password_P5_SetWheel)    /*输入设置密码界面或者输入轮径密码界面，长按i键，返回主界面*/
                {
                    vBsp_LCD_Clear();
                    return Page_MainPage;    /*转主界面*/
                }
                break;
            }
            }
        }
    }
}

/******************************************************************************
** 功  能：调节电压分段界面
** 参  数：无
** 返回值：从该界面退出后，要转入的界面类型
** 备  注：
******************************************************************************/
En_FunResponse xDisp_DispVoltageSegment(void)
{
    muilt_cyc_fifo_error_code_t lxState;
    uint16_t                    lxActualReadLen;
    uint16_t                     lusKeyValue;
    uint8_t                     lucSegment_Index;
    uint32_t                    lulTicks;
    uint16_t *                  lpVoltLevel;
    char                        lucText[7];
    uint8_t                     n;

    vPROTOCOL_Set_Pas(0);           /*设置界面发0档*/
    lulTicks = ulBsp_Getticks();    /*记录以下进入设置时的时间戳，用于判断超时退出*/
    lucSegment_Index = 1;           /*从第一段开始*/

    if(gtParam.Volt == 36)
    {
        lpVoltLevel = &gtParam.V_36_Tab[0];
    }
    else if(gtParam.Volt == 48)
    {
        lpVoltLevel = &gtParam.V_48_Tab[0];
    }
    else if(gtParam.Volt == 52)
    {
        lpVoltLevel = &gtParam.V_52_Tab[0];
    }

    while(1)
    {
        /*底部的横线*/
        vBsp_LCD_DispICO_Line(1);
        /*MENU图标，显示*/
        vBsp_LCD_DispICO_Menu(1);

        /*显示电量段数*/
        vBsp_LCD_DispBatteryBar(lucSegment_Index,ON);

        /*速度区显示当前电量段的电压值*/
        vBsp_LCD_DispSpeedNum(lpVoltLevel[lucSegment_Index - 1],ON);

        /*底部显示VOL1-VOL5字样*/
        sprintf(lucText,"UOL%d",lucSegment_Index);
        vBsp_LCD_DispStringAtBottom(lucText,0,ON);


        if(ulBsp_Getticks() - lulTicks > CONFIG_EXTI_TIME * 1000)
        {
            vExit_Setting_Without_Saving();     /*超时退出，不保存设置*/
            vBsp_LCD_DispAll();
            vBsp_DelayMs(500);
            vBsp_LCD_Clear();
            return Page_MainPage;    /*全显0.5秒后，转主界面*/
        }

        /*从按键缓存中读取键值，并根据键值执行相应的动作*/
        MCF_ReadDataFromFifo(KEY_FIFO_ID,2,(uint8_t *)&lusKeyValue,&lxActualReadLen,&lxState);/*从队列中取出一组键值*/
        if(lxActualReadLen == 2 && lxState == kMultiCycFiFo_Error_NONE)
        {
            lulTicks = ulBsp_Getticks();        /*有任何按键按下，都会复位自动退出超时计数*/
            switch(lusKeyValue)
            {
            case BUTTON_UP_RELEASE:     /*加键释放*/
            {
                if(lpVoltLevel[lucSegment_Index - 1] < 600)    /*调整上限值60.0V*/
                {
                    lpVoltLevel[lucSegment_Index - 1]++;
                }
                /*遍历所有电压分段，看是否有低段的电压值高于高段的，如果有，将高段电压调整为低段电压值+0.1V*/
                for(n = 0; n < 4; n++)
                {
                    if(lpVoltLevel[n] >= lpVoltLevel[n + 1])
                    {
                        lpVoltLevel[n + 1] = lpVoltLevel[n] + 1;    /*高段的电压值调整为低端电压值+0.1V*/
                    }
                }
                break;
            }
            case BUTTON_DOWN_RELEASE:    /*减键释放*/
            {
                if(lpVoltLevel[lucSegment_Index - 1] > 200)     /*调整下限是20.0V*/
                {
                    lpVoltLevel[lucSegment_Index - 1]--;
                }
                /*遍历所有电压分段，看是否有高段的电压值低于低段的，如果有，将低段电压调整为高段电压值-0.1V*/
                for(n = 4; n > 0; n--)
                {
                    if(lpVoltLevel[n] <= lpVoltLevel[n - 1])
                    {
                        lpVoltLevel[n - 1] = lpVoltLevel[n] - 1;    /*高段的电压值调整为低端电压值+0.1V*/
                    }
                }
                break;
            }
            case BUTTON_MODE_LONG:        /*i键长按*/
            {
                vBsp_LCD_Clear();
                return Page_AdvancedSetting;    /*退回到高级设置菜单*/
            }
            case BUTTON_MODE_RELEASE:   /*i键释放*/
            {
                if(++lucSegment_Index > 5)
                {
                    lucSegment_Index = 1;
                }
                break;
            }
            }
        }
    }
}
/******************************************************************************
** 功  能：调节档位范围及助力比界面
** 参  数：无
** 返回值：从该界面退出后，要转入的界面类型
** 备  注：
******************************************************************************/

En_FunResponse xDisp_DispSca_PasRange(void)
{
    muilt_cyc_fifo_error_code_t lxState;
    uint16_t                    lxActualReadLen;
    uint16_t                     lusKeyValue;
    uint8_t                     lucPasRange_Index;
    uint32_t                    lulTicks;
    uint8_t *                   lpPas_Pwm;
    char                        lucText[7];
    char                        lucValue[3];
    uint8_t                     n;


    lulTicks = ulBsp_Getticks();    /*记录以下进入设置时的时间戳，用于判断超时退出*/
    lucPasRange_Index = 1;           /*从第一段开始*/

    if(gtParam.Pas_Max == 3)
    {
        lpPas_Pwm = &gtParam.PWM0_3[0];
    }
    else if(gtParam.Pas_Max == 5)
    {
        lpPas_Pwm = &gtParam.PWM0_5[0];
    }
    else if(gtParam.Pas_Max == 7)
    {
        lpPas_Pwm = &gtParam.PWM0_7[0];
    }
    else if(gtParam.Pas_Max == 9)
    {
        lpPas_Pwm = &gtParam.PWM0_9[0];
    }

    while(1)
    {
        /*底部的横线*/
        vBsp_LCD_DispICO_Line(1);
        /*MENU图标，显示*/
        vBsp_LCD_DispICO_Menu(1);

        /*底部显示VOL1-VOL5字样*/
        //sprintf(lucText,"%d",gtParam.Pas_Max);
        sprintf(lucText,"%d-%d-",gtParam.Pas_Max,lucPasRange_Index);
        vBsp_LCD_DispStringAtBottom(lucText,0,ON);

        sprintf(lucValue,"%d",lpPas_Pwm[lucPasRange_Index - 1]);
        vBsp_LCD_DispStringAtBottom(lucValue,4,ucBsp_GetFlashFlag());

        if(ulBsp_Getticks() - lulTicks > CONFIG_EXTI_TIME * 1000)
        {
            vExit_Setting_Without_Saving();     /*超时退出，不保存设置*/
            vBsp_LCD_DispAll();
            vBsp_DelayMs(500);
            vBsp_LCD_Clear();
            return Page_MainPage;    /*全显0.5秒后，转主界面*/
        }

        /*从按键缓存中读取键值，并根据键值执行相应的动作*/
        MCF_ReadDataFromFifo(KEY_FIFO_ID,2,(uint8_t *)&lusKeyValue,&lxActualReadLen,&lxState);/*从队列中取出一组键值*/
        if(lxActualReadLen == 2 && lxState == kMultiCycFiFo_Error_NONE)
        {
            lulTicks = ulBsp_Getticks();        /*有任何按键按下，都会复位自动退出超时计数*/
            switch(lusKeyValue)
            {
            case BUTTON_UP_RELEASE:     /*加键释放*/
            {

                if(++lpPas_Pwm[lucPasRange_Index - 1] > 100)
                {
                    lpPas_Pwm[lucPasRange_Index - 1] = 0;
                }

                break;
            }
            case BUTTON_DOWN_RELEASE:    /*减键释放*/
            {
                if(lpPas_Pwm[lucPasRange_Index - 1]-- == 0)
                {
                    lpPas_Pwm[lucPasRange_Index - 1] = 100;
                }
                break;
            }
            case BUTTON_MODE_LONG:        /*i键长按*/
            {
                vBsp_LCD_Clear();
                return Page_AdvancedSetting;    /*退回到高级设置菜单*/
            }
            case BUTTON_MODE_RELEASE:   /*i键释放*/
            {
                if(++lucPasRange_Index > gtParam.Pas_Max)
                {
                    lucPasRange_Index = 1;
                }
                break;
            }
            }
        }
    }


}

/******************************************************************************
** 功  能：716仪表恢复出厂设置界面显示
** 参  数：无
** 返回值：无
** 备  注：
******************************************************************************/
En_FunResponse xDisp_Set_Default(void)
{
    muilt_cyc_fifo_error_code_t lxState;
    uint16_t                    lxActualReadLen;
    uint16_t                     lusKeyValue;
    uint32_t                    lulTicks;
    uint8_t                     lucSetDefault = 0;

    vPROTOCOL_Set_Pas(0);           /*设置界面发0档*/
    lulTicks = ulBsp_Getticks();    /*记录以下进入设置时的时间戳，用于判断超时退出*/
    while(1)
    {
        /*底部的横线*/
        vBsp_LCD_DispICO_Line(1);
        /*MENU图标，显示*/
        vBsp_LCD_DispICO_Menu(1);

        /*根据选择，显示不同的调节参数*/
        if(lucSetDefault == 0)
        {
            vBsp_LCD_DispStringAtBottom("DEF-n",0,ON);
        }
        else
        {
            vBsp_LCD_DispStringAtBottom("DEF-y",0,ON);
        }

        if(ulBsp_Getticks() - lulTicks > CONFIG_EXTI_TIME * 1000)
        {
            vExit_Setting_Without_Saving();     /*超时退出，不保存设置*/
            vBsp_LCD_DispAll();
            vBsp_DelayMs(500);
            vBsp_LCD_Clear();
            return Page_MainPage;    /*全显0.5秒后，转主界面*/
        }

        /*从按键缓存中读取键值，并根据键值执行相应的动作*/
        MCF_ReadDataFromFifo(KEY_FIFO_ID,2,(uint8_t *)&lusKeyValue,&lxActualReadLen,&lxState);/*从队列中取出一组键值*/
        if(lxActualReadLen == 2 && lxState == kMultiCycFiFo_Error_NONE)
        {
            lulTicks = ulBsp_Getticks();        /*有任何按键按下，都会复位自动退出超时计数*/
            switch(lusKeyValue)
            {
            case BUTTON_UP_RELEASE:     /*加键释放*/
            {
                lucSetDefault = lucSetDefault == 0 ? 1:0;
                break;
            }
            case BUTTON_DOWN_RELEASE:    /*减键释放*/
            {
                lucSetDefault = lucSetDefault == 0 ? 1:0;
                break;
            }
            case BUTTON_MODE_RELEASE:   /*i键释放*/
            {
                if(lucSetDefault == 0)
                {
                    vBsp_LCD_DispAll();
                    vBsp_DelayMs(500);
                    vBsp_LCD_Clear();
                    return Page_MainPage;    /*全显0.5秒后，转主界面*/
                }
                break;
            }
            case BUTTON_MODE_LONG:      /*长按i键*/
            {
                if(lucSetDefault == 1)
                {
                    vParam_ResetConfig(&gtParam);       /*复位参数*/
                    lucSetDefault = 0;
                    vExit_Setting_With_Saving();    /*保存参数*/
                }
                vBsp_LCD_DispAll();
                vBsp_DelayMs(500);
                vBsp_LCD_Clear();
                return Page_MainPage;    /*全显0.5秒后，转主界面*/
            }

            }
        }
    }
}

/******************************************************************************
** 功  能：716仪表显示版本号界面
** 参  数：无
** 返回值：无
** 备  注：
******************************************************************************/
En_FunResponse xDisp_DispVersion(void)
{
    uint32_t                    lulTicks;
    muilt_cyc_fifo_error_code_t lxState;
    uint16_t                    lxActualReadLen;
    uint16_t                     lusKeyValue;

    lulTicks = ulBsp_Getticks();

    while(1)
    {
        /*速度区显示软件号，已字符串的形式显示*/
        vBsp_LCD_DispStringAtSpeed(SOFTWARE,ON);

        /*ODO区域，显示版本号，以字符串的形式显示*/
        vBsp_LCD_DispStringAtBottom(VER,0,ON);      /*左起顶格显示*/


        if(ulBsp_Getticks() - lulTicks > 60000)
        {
            vExit_Setting_Without_Saving();     /*超时退出，不保存设置*/
            vBsp_LCD_DispAll();
            vBsp_DelayMs(500);
            vBsp_LCD_Clear();
            return Page_MainPage;    /*全显0.5秒后，转主界面*/
        }

        /*从按键缓存中读取键值，并根据键值执行相应的动作*/
        MCF_ReadDataFromFifo(KEY_FIFO_ID,2,(uint8_t *)&lusKeyValue,&lxActualReadLen,&lxState);/*从队列中取出一组键值*/
        if(lxActualReadLen == 2 && lxState == kMultiCycFiFo_Error_NONE)
        {
            switch(lusKeyValue)
            {
            case BUTTON_UP_RELEASE:     /*加键释放*/
            {
                break;
            }
            case BUTTON_DOWN_RELEASE:    /*减键释放*/
            {
                break;
            }
            case BUTTON_UP_LONG:        /*加减长按*/
            {
                break;
            }
            case BUTTON_MODE_LONG:      /*i键长按*/
            {
                vExit_Setting_With_Saving();    /*保存参数*/
                vBsp_LCD_DispAll();
                vBsp_DelayMs(500);
                vBsp_LCD_Clear();
                return Page_MainPage;    /*全显0.5秒后，转主界面*/
            }
            case BUTTON_POWER_LONG: /*电源键长按*/
            {
                vPowerOff();
                break;
            }
            }
        }
    }
}


/******************************************************************************
** 功  能：USB充电时的界面
** 参  数：无
** 返回值：无
** 备  注：
******************************************************************************/
En_FunResponse xDisp_DispUsbCharging(void)
{
    uint32_t lulTicks;
    muilt_cyc_fifo_error_code_t lxState;
    uint16_t lxActualReadLen;
    uint16_t lusKeyValue;
    lulTicks = ulBsp_Getticks(); //
    vBsp_LCD_Clear();
    while (1)
    {
        if (gucUSBstate == 0)
        {
            vPowerOff();
        }

        vBsp_LCD_DispICO_USB(gucUSBstate);



        /*从按键缓存中读取键值，并根据键值执行相应的动作*/
        MCF_ReadDataFromFifo(KEY_FIFO_ID, 2, (uint8_t *)&lusKeyValue, &lxActualReadLen, &lxState); /*从队列中取出一组键值*/
        if (lxActualReadLen == 2 && lxState == kMultiCycFiFo_Error_NONE)
        {
            switch (lusKeyValue)
            {
            case BUTTON_UP_RELEASE:   /*加键释放*/
            case BUTTON_DOWN_RELEASE: /*减键释放*/
            case BUTTON_UP_LONG:      /*加减长按*/
            case BUTTON_MODE_LONG:    /*i键长按*/
            case BUTTON_MODE_RELEASE:
            case BUTTON_R_RELEASE:
            case BUTTON_L_RELEASE:
            {
                break;
            }
            case BUTTON_POWER_LONG: /*电源键长按*/
            {
                vPowerOff();
            }
            }
        }
    }
}

/******************************************************************************
** 功  能：设置进入或退出密码界面
** 参  数：State-状态，0-退出密码界面，1-进入密码界面
** 返回值：无
** 备  注：
******************************************************************************/
void vSetInPassword(uint8_t State)
{
    gucInPasswordFlag = State;
}

/******************************************************************************
** 功  能：获取当前是否处于密码界面
** 参  数：无
** 返回值：0-不在密码界面，1-在密码界面
** 备  注：
******************************************************************************/
uint8_t ucGetIsInPassword(void)
{
    return gucInPasswordFlag;
}

